package cn.tedu.ivos.dict.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.dict.pojo.dto.DictQuery;
import cn.tedu.ivos.dict.pojo.dto.DictSaveParam;
import cn.tedu.ivos.dict.pojo.vo.DictVO;
import cn.tedu.ivos.dict.service.DictService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;

@RestController
@RequestMapping("/v1/dict")
@Slf4j
public class DictController {
    @Autowired
    DictService dictService;

    @Operation(summary = "根据字典类型查询字典数据")
    @ApiOperationSupport(order = 10)
    @GetMapping("select")
    public JsonResult select(DictQuery dictQuery){
        log.debug("根据字典类型查询字典数据,参数:{}",dictQuery);
        List<DictVO> list = dictService.select(dictQuery);
        return JsonResult.ok(list);
    }
    @Operation(summary = "根据字典类型删除字典数据")
    @ApiOperationSupport(order = 20)
    @PostMapping("delete/{id}")
    public JsonResult delete(@PathVariable Long id){
        log.debug("根据字典类型删除字典数据,参数:{}",id);
        dictService.delete(id);
        return JsonResult.ok();
    }
    @Operation(summary = "新增字典数据")
    @ApiOperationSupport(order = 30)
    @PostMapping("add")
    public JsonResult add(DictSaveParam dictSaveParam){
        log.debug("新增字典数据,参数:{}",dictSaveParam);
        dictService.add(dictSaveParam);
        return JsonResult.ok();
    }

}
